const COS = require("../static/cos-wx-sdk-v5.js");
const Bucket = "jianji-1259268558"; // 存储桶的名称，命名规则为 BucketName-APPID，此处填写的存储桶名称必须为此格式
const Region = "ap-shanghai"; // 存储桶所在地域
// 创建一个 COS SDK 实例
const cos = new COS({
  SecretId: "AKID3CF8rPlxAD6oMp8JKBrMbDsVVapGnXKE",
  SecretKey: "BSiu6ANmHzrlbTONJ87nRyMfprkX0Nct",
});
export default {
  // 删除文件
  deleteFileToTencentClound(Key) {
    return new Promise((resolve, reject) => {
      cos.deleteObject(
        {
          Bucket: Bucket,
          Region: Region,
          Key: Key,
        },
        function (err, data) {
          console.log(err || data);
          resolve(data);
        }
      );
    });
  },
  // 上传文件
  uploadFileToTencentClound(filename, filePath) {
    return new Promise((resolve, reject) => {
      cos.postObject(
        {
          Bucket: Bucket,
          Region: Region,
          Key: "wxFile/" + filename,
          FilePath: filePath,
          onProgress: function (info) {
            console.log("[cos.postObject-seccess]", JSON.stringify(info));
          },
        },
        function (err, data) {
          console.log("[cos.postObject-err]", err || data);
          resolve(data.Location);
        }
      );
    });
  },
};
